package create;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import database.Student;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.Date;
import java.awt.event.ActionEvent;
public class StuInfo extends JFrame {

	private JPanel contentPane;
	Student s = new Student();
	private JTextField name;
	private JTextField id;
	private JTextField schoolDepartment;
	private JTextField birth;
	private JTextField collegetime;
	private JTextField nation;
	private JTextField address;
	private JTextField nativePlace;
	private JTextField personalID;
	private String sex;
	private String politics;
	private int flag = 1;//区分老师还是学生
	private JTextField classNumText;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					StuInfo frame = new StuInfo();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public StuInfo() {
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(600, 300, 734, 482);
		setLocationRelativeTo(getOwner());
		setResizable(false);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("姓名");
		lblNewLabel.setBounds(29, 89, 68, 29);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("学号");
		lblNewLabel_1.setBounds(29, 130, 68, 29);
		contentPane.add(lblNewLabel_1);
		
		JLabel label = new JLabel("性别");
		label.setBounds(29, 171, 68, 29);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("院系");
		label_1.setBounds(29, 212, 68, 29);
		contentPane.add(label_1);
		
		JLabel label_2 = new JLabel("生日");
		label_2.setBounds(29, 253, 68, 29);
		contentPane.add(label_2);
		
		JLabel label_3 = new JLabel("入学时间");
		label_3.setBounds(29, 295, 68, 29);
		contentPane.add(label_3);
		
		JLabel label_4 = new JLabel("政治面貌");
		label_4.setBounds(29, 336, 68, 29);
		contentPane.add(label_4);
		
		JLabel label_5 = new JLabel("籍贯");
		label_5.setBounds(425, 89, 68, 29);
		contentPane.add(label_5);
		
		JLabel label_6 = new JLabel("家庭住址");
		label_6.setBounds(425, 130, 68, 29);
		contentPane.add(label_6);
		
		JLabel label_7 = new JLabel("国籍");
		label_7.setBounds(425, 171, 68, 29);
		contentPane.add(label_7);
		
		name = new JTextField();
		name.setBounds(114, 90, 130, 26);
		contentPane.add(name);
		name.setColumns(10);
		
		id = new JTextField();
		id.setColumns(10);
		id.setBounds(114, 131, 130, 26);
		contentPane.add(id);
		id.addKeyListener(new KeyAdapter(){  
            public void keyTyped(KeyEvent e) {  
                int keyChar = e.getKeyChar();                 
                if(keyChar >= KeyEvent.VK_0 && keyChar <= KeyEvent.VK_9){  
                }else{  
                    e.consume();   
                }  
            }  
        }); 
		
		
		
		
		schoolDepartment = new JTextField();
		schoolDepartment.setColumns(10);
		schoolDepartment.setBounds(109, 213, 130, 26);
		contentPane.add(schoolDepartment);
		
		birth = new JTextField();
		birth.setColumns(10);
		birth.setBounds(109, 254, 130, 26);
		contentPane.add(birth);
		
		collegetime = new JTextField();
		collegetime.setColumns(10);
		collegetime.setBounds(109, 296, 130, 26);
		contentPane.add(collegetime);
		
		nation = new JTextField();
		nation.setColumns(10);
		nation.setBounds(488, 172, 130, 26);
		contentPane.add(nation);
		
		address = new JTextField();
		address.setColumns(10);
		address.setBounds(488, 130, 130, 26);
		contentPane.add(address);
		
		nativePlace = new JTextField();
		nativePlace.setColumns(10);
		nativePlace.setBounds(488, 90, 130, 26);
		contentPane.add(nativePlace);
		
		classNumText = new JTextField();
		classNumText.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
			}
		});
		classNumText.setColumns(10);
		classNumText.setBounds(488, 251, 130, 26);
		contentPane.add(classNumText);
		
		JRadioButton rdbtnNewRadioButton = new JRadioButton("男");
		rdbtnNewRadioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sex = "男";
				s.setSex(sex);
			}
		});
		rdbtnNewRadioButton.setBounds(94, 173, 83, 23);
		contentPane.add(rdbtnNewRadioButton);
		
		JRadioButton radioButton = new JRadioButton("女");
		radioButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sex = "女";
				s.setSex(sex);
			}
		});
		radioButton.setBounds(204, 173, 83, 23);
		contentPane.add(radioButton);
		ButtonGroup b = new ButtonGroup();
		b.add(radioButton);
		b.add(rdbtnNewRadioButton);//添加分组使其成为二选一
		
		
		JRadioButton radioButton_1 = new JRadioButton("团员");
		radioButton_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				politics = "团员";
				s.setPolitics(politics);
			}
		});
		radioButton_1.setBounds(94, 336, 83, 23);
		contentPane.add(radioButton_1);
		
		JRadioButton radioButton_2 = new JRadioButton("党员");
		radioButton_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				politics = "党员";
				s.setPolitics(politics);
			}
		});
		radioButton_2.setBounds(204, 338, 83, 23);
		contentPane.add(radioButton_2);
		
		JRadioButton radioButton_3 = new JRadioButton("无");
		radioButton_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				politics = "无";
				s.setPolitics(politics);
			}
		});
		radioButton_3.setBounds(312, 338, 83, 23);
		contentPane.add(radioButton_3);
		
		ButtonGroup b1 = new ButtonGroup();
		b1.add(radioButton_1);
		b1.add(radioButton_2);
		b1.add(radioButton_3);
		
		JButton button = new JButton("下一步");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				s.setPersonalID(Integer.parseInt(personalID.getText()));
				s.setName(name.getText());
				s.setId(Integer.parseInt(id.getText()));
				s.setBirth(birth.getText());
				s.setSchool_department(schoolDepartment.getText());
				s.setAdress(address.getText());
				s.setCollege_time(Integer.parseInt(collegetime.getText()));
				s.setPolitics(politics);
				s.setNative_place(nativePlace.getText());
				s.setNation(nation.getText());
				s.setClassNum(Integer.parseInt(classNumText.getText()));
				if (new Create().InputStuInfo(s) == false){
					JOptionPane.showMessageDialog(null,"输入错误，请重新输入","信息提示框",JOptionPane.INFORMATION_MESSAGE);
					new StuInfo();
					setVisible(false);
				}
				
				new PwdInfo(flag,Integer.parseInt(id.getText()));
				setVisible(false);
			}
		});
		button.setBounds(555, 381, 117, 29);
		contentPane.add(button);
		
		JButton button_1 = new JButton("清空");
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new StuInfo();
			}
		});
		button_1.setBounds(390, 381, 117, 29);
		contentPane.add(button_1);
		
		JButton button_2 = new JButton("上一步");
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new CreateUser();
				setVisible(false);
			}
		});
		button_2.setBounds(214, 381, 117, 29);
		contentPane.add(button_2);
		
		JLabel lblNewLabel_2 = new JLabel("学生信息");
		lblNewLabel_2.setFont(new Font("Lucida Grande", Font.PLAIN, 25));
		lblNewLabel_2.setBounds(312, 27, 106, 31);
		contentPane.add(lblNewLabel_2);
		
		JLabel lblxxxx = new JLabel("(格式:xxxx-xx-xx)");
		lblxxxx.setBounds(238, 259, 137, 16);
		contentPane.add(lblxxxx);
		
		personalID = new JTextField();
		personalID.setBounds(488, 213, 130, 26);
		contentPane.add(personalID);
		personalID.setColumns(10);
		
		JLabel label_8 = new JLabel("身份证号");
		label_8.setBounds(425, 212, 68, 29);
		contentPane.add(label_8);
		
		JLabel label_9 = new JLabel("班级");
		label_9.setBounds(425, 253, 68, 29);
		contentPane.add(label_9);
		
		
	}
}
